package com.blog.controller;

import com.jfinal.core.Controller;
import com.blog.kit.StringKit;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Logger;

/**
 * Created by wangjian on 16/9/14.
 */
public class BaseController extends Controller {

    private static final int TIPS_COOKIE_MAX_AGE_IN_SECONDS = 3;
    public static final String ERROR_MSG_COOKIE_NAME = "error_msg";

    @Override
    public String getPara(String name) {
        return super.getPara(name, "").trim();
    }

    /**
     * 设置错误消息至Cookie中
     *
     * @param error_msg
     */
    public void setErrorCookie(String error_msg) {
        try {
                setCookie(ERROR_MSG_COOKIE_NAME, URLEncoder.encode(error_msg, "utf-8"),
                        TIPS_COOKIE_MAX_AGE_IN_SECONDS);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    public void getErrorCookie(){
        try {
            setAttr(ERROR_MSG_COOKIE_NAME, URLDecoder.decode(getCookie(ERROR_MSG_COOKIE_NAME), "utf-8"));
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
